// import Home from '@/pages/Home'  //路由懒加载，当跳转这个路由时才开始加载组件
import Register from '@/pages/Register'
import List from '@/pages/List'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Login from '@/pages/Login'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'

// 这个con 是promise类型的
// const con = ()=>{
//   return import('@/pages/Home')  //这里可以以这种方式import引入组件
// }

export default [
  {
    path: '/home',
    // component: con  //可以直接按下面的方法引入
    component: () => import('@/pages/Home'),
    meta: {
      show: true,
    },
  },
  {
    path: '/register',
    component: Register,
    meta: {
      show: false,
    },
  },
  {
    path: '/login',
    component: Login,
    meta: {
      show: true,
    },
  },
  {
    name: 'listName',
    // 使用占位符声明接受传来的parmas参数   path:'/list/:keyword',这里的keyword不确定是否有值，所有要加“？”
    path: '/list/:keyword?',
    component: List,
    meta: {
      show: true,
    },
    // 页面上需要获取数据时可以使用props
    // props($route){
    //     return{
    //         keyword:$route.params.keyword,
    //         k:$route.query.k,
    //     }
    // }
  },
  {
    name: 'detail',
    path: '/detail/:skuId',
    component: Detail,
    meta: {
      show: true,
    },
  },
  {
    path: '/addcartsuccess',
    name: 'addcartsuccess',
    component: AddCartSuccess,
    meta: { show: true },
  },
  {
    path: '/shopcart',
    name: 'shopcart',
    component: ShopCart,
    meta: { show: true },
  },
  {
    path: '/trade',
    name: 'trade',
    component: Trade,
    meta: { show: true },
    // 独享守卫
    beforeEnter: (to, from, next) => {
      // 去交易页面，必须是从购物车而来的
      if(from.path == "/shopcart"){
        next()
      }else{
        // 其他组件停留在当前
        next(false)
      }
    }

  },
  {
    path: '/pay',
    name: 'pay',
    component: Pay,
    meta: { show: true },
     // 独享守卫
     beforeEnter: (to, from, next) => {
      // 去支付页面，必须是从交易而来的
      if(from.path == "/trade"){
        next()
      }else{
        // 其他组件停留在当前
        next(false)
      }
    }
  },
  {
    path: '/paysuccess',
    name: 'paysuccess',
    component: PaySuccess,
    meta: { show: true },
  },
  {
    path: '/center',
    name: 'center',
    component: Center,
    meta: { show: true },
    // 二级路由组件
    children: [
      {
        path: 'groupOrder',
        name: 'groupOrder',
        component: GroupOrder,
        meta: { show: true },
      },
      {
        path: 'myOrder',
        name: 'myOrder',
        component: MyOrder,
        meta: { show: true },
      },
      // 进center后重定向到myOrder中，否则不点的话右侧部分是空的
      {
        path: '/center',
        redirect: '/center/myOrder',
      },
    ],
  },
  // 重定向到home
  {
    path: '*',
    redirect: '/home',
  },
]
